import axios from "axios";
import { Toast } from "vant";

export default{
    install(vue){
        var auth=vue.prototype.$auth
        let service=axios.create({
            baseURL:'http://10.30.230.2:9000/'
        })
        service.interceptors.request.use(request=>{
            request.headers.Authorization=auth.getAuthorization()
            return request
        })
        service.interceptors.response.use(response=>{
            console.log(response)
            if(response.status!==200){

                Toast.fail({
                    duration:0,
                    overlay:true,
                    closeOnClickOverlay:true,
                    closeOnClick:true,
                    message:"请求异常",
                })
                return Promise.reject(res)
            }
            const res=response.data
            if(res.data!==0){
                console.log(res)
                // Toast.fail({
                //     duration:0,
                //     overlay:true,
                //     closeOnClickOverlay:true,
                //     closeOnClick:true,
                //     message:res.msg,
                // })
                return Promise.resolve(res)
            }
            return res
        })
        vue.prototype.$http=service
    }
}